const http = require('http')
const WebSocket = require('ws');
const express = require('express')
const app = express()
app.use(express.static('public'))
const server = http.createServer(app)

const wss = new WebSocket.Server({ server })
const clients = []



wss.on('connection', function connection(ws) {
    clients.push(ws)
    ws.on('message', function incoming(message) {
        clients.filter(i => i != ws).forEach(i => i.send(message))
    });
});

server.listen(3000)